﻿using GRPCClass;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GRPCClass
{
    public class TaskRequestCollection : IList
    {
        public List<TaskRequest> TaskRequestList = new List<TaskRequest>();
      
        public object this[int index]
        {
            get
            {
                return TaskRequestList[index];
            }
            set
            {
                TaskRequest a = value as TaskRequest;
                TaskRequestList[index] = a;
            }
        }

        public int Count
        {
            get
            {
                return TaskRequestList.Count;
            }   
        }

        public object SyncRoot
        {
            get
            {
                return this;
            }
        }

        public bool IsSynchronized
        {
            get
            {
                return false;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public bool IsFixedSize
        {
            get
            {
                return true;
            }
        }
        public Boolean Remove(TaskRequest vtaskreply)
        {
            TaskRequest ftr = findTaskReply(vtaskreply);
            if (ftr != null)
            {
                TaskRequestList.Remove(ftr);
                return true;
            }
            return false;
        }
        
        public int Add(object value)
        {
            TaskRequest a = value as TaskRequest;
            if (a != null)
            {
                if (findTaskReply(a)==null)
                {
                    TaskRequestList.Add(a); 
                    return 1;
                }
            } 
            return 0;
        }

        public TaskRequest findTaskReply(TaskRequest tr)
        {
           

            for (int i = 0; i < TaskRequestList.Count; i++)
            {
               
                if (TaskRequestList[i].ID == tr.ID)
                {
                    return TaskRequestList[i];
                }
            }

            return null; 
        }
        public void Clear()
        {
            TaskRequestList.Clear();
        }

        public bool Contains(object value)
        {
          return TaskRequestList.Contains(value);
        }

        public void CopyTo(Array array, int index)
        {
            TaskRequestList.CopyTo(array as TaskRequest[], index);
        }

        public IEnumerator GetEnumerator()
        {
            return TaskRequestList.GetEnumerator();
        }

        public int IndexOf(object value)
        {
            return TaskRequestList.IndexOf(value as TaskRequest);
        }

        public void Insert(int index, object value)
        {
            TaskRequestList.Insert(index, value as TaskRequest);
        }

        public void Remove(object value)
        {
            TaskRequestList.Remove(value as TaskRequest);
        }

        public void RemoveAt(int index)
        {
            TaskRequestList.RemoveAt(index);
        }
    }
}
